import Vue from "vue";
import VueRouter from "vue-router";
Vue.use(VueRouter);
const router = new VueRouter({
  mode: "hash",
  routes: [
    {
      path: "/",
      redirect: "/home",
    },
    {
      path: "/home",
      name: "home",
      component: () => import("@/views/first-level/Home.vue"),
      children: [
        {
          path: "userslist",
          name: "userslist",
          component: () => import("@/views/second-level/UsersList.vue"),
        },
      ],
    },
    {
      path: "/login",
      name: "login",
      component: () => import("@/views/first-level/Login.vue"),
    },
  ],
});
// router.beforeEach((to,from,next)=>{
//     if(to.path == '/login'){//如果要去的路径是登录
//         return next();//放行 并且下面代码不执行
//     }
//     if(!window.sessionStorage.getItem('token')){//如果查询不到token
//         return next('/login')//只能去登录页面
//     }
//     next();
// })
export default router;
